package com.itheima.sh.b_response_02;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*
    说明：
        1.重定向也可以完成资源间的跳转，多次请求和多次响应
        2.地址栏发送改变，记录着最后一次的请求地址
        3.属于服务器外部的跳转行为
        4.实现重定向方式：
            方式一：
                 response.setStatus(302);
                 response.setHeader("location","/day13/responseDemo02Servlet");
            方式二：掌握
                 response.sendRedirect("/day13/responseDemo02Servlet");
 */
@WebServlet("/responseDemo01Servlet")
public class ResponseDemo01Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("responseDemo01Servlet,A");


        if (true) {
            request.setAttribute("msg", "suoge");
        request.getRequestDispatcher("/responseDemo02Servlet").forward(request,response);
        }else {

            response.setStatus(302);
            response.setHeader("location", "/day08/responseDemo02Servlet");

        }
    }
}
